package common;

import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.openqa.selenium.By;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;

import java.util.concurrent.TimeUnit;

public class InitAndClose {
    public static WebDriver webDriver;

    @BeforeAll
    public static void setUp() {
        webDriver = new ChromeDriver();
    }

    @AfterAll
    public static void tearDown() {
        webDriver.quit();
    }

    // 使用 zhangsan 用户登陆
    public void login() {
        String username = "zhangsan";
        String password = "123456";
        webDriver.get("http://8.130.172.144:8081/login.html");
        // 等待页面加载完成
        webDriver.manage().timeouts().implicitlyWait(3, TimeUnit.MINUTES);
        // 输入账号
        webDriver.findElement(By.cssSelector("#username")).sendKeys(username);
        // 输入密码并按下回车
        webDriver.findElement(By.cssSelector("#password")).sendKeys(password, Keys.ENTER);
    }
}
